package GreedyAlgorithmPackage;

import org.junit.jupiter.api.Test;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Lzm
 * @version 1.0
 */
public class lemonadeChange_ {
  @Test
  public void lemonadeChangeTest(){
    int[] bills = new int[]{5,5,10,10,20};
    System.out.println(lemonadeChange(bills));

  }

  public boolean lemonadeChange(int[] bills) {
    if (bills[0] != 5){
      return false;
    }
    int totalMoney = 0;
    int five = 0;
    int ten = 0;
    int twenty = 0;
    for (int bill : bills) {
      if (bill == 5){
        five++;
      }
      if (bill == 10){
        if (five < 1){
          return false;
        }
        else{
          five--;
          ten++;
        }
      }
      if (bill == 20){
        if (ten > 0 && five > 0){
          ten--;
          five--;
          twenty++;
        }
        else{
          if (five >= 3){
            five -= 3;
            twenty++;
          }
          else{
            return false;
          }
        }
      }
    }
    return true;
  }
}
